<template>
  <el-card shadow="hover">
    <template #header>
      <div class="card-header">
        <el-input v-model="input" placeholder="请输入订单号" clearable style="width: 200px;margin-right: 10px;" />
        <el-select v-model="value" class="m-2" placeholder="Select" style="margin-right: 10px;">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <el-button class="button" color="#1baeae" :icon="HomeFilled">配货完成</el-button>
        <el-button class="button" color="#1baeae" :icon="HomeFilled">出货</el-button>
        <el-button class="button" color="#f56c6c" :icon="Delete">关闭订单</el-button>
      </div>
    </template>
    <el-table ref="multipleTableRef" :data="state.tableData" style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" />
      <el-table-column property="orderNo" label="订单号" />
      <el-table-column property="totalPrice" label="订单总价" />
      <el-table-column label="订单状态">
        <template #default="{row}">
          <span>{{status(row.orderStatus)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付方式">
        <template #default="{row}">
          <span>{{payType(row.payType)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间">
        <template #default="scope">{{ scope.row.createTime }}</template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="{ row }">
          <el-link type="success" @click="update(row)" :underline="false">关闭订单&nbsp;&nbsp;</el-link>
          <el-link type="primary" @click="subordinate(row.goodsSellStatus,[row.goodsId])" :underline="false">&nbsp;订单详情&nbsp;</el-link>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
  <el-pagination background layout="prev, pager, next" :total="state.total" :page-size="state.pageSize"
    @prev-click="prevClick" @next-click="nextClick" @current-change="currentChange" />
</template>

<script>
  export default {
    name: 'indentAdministration',
  }
</script>

<script setup>
  import {
    Delete,
    HomeFilled
  } from '@element-plus/icons-vue'
  import {
    ref,reactive,onBeforeMount
  } from "vue"
  import api from '@/http'
    import {
    ElMessage
  } from 'element-plus'
  const state = reactive({
    tableData: [],
    total: 0,
    pageSize: 10,
    currentPage: 1,
    loading: false,
    selectionList:[],
  })
  const options = [
  {
    value: '',
    label: '全部',
  },
  {
    value: 0,
    label: '待支付',
  },
  {
    value: 1,
    label: '已支付',
  },
  {
    value: 2,
    label: '配货完成',
  },
  {
    value: 3,
    label: '出库成功',
  },
  {
    value: 4,
    label: '交易成功',
  },
  {
    value: -1,
    label: '手动关闭',
  },
  {
    value: -2,
    label: '超时关闭',
  },
  {
    value: -3,
    label: '商家关闭',
  },
]
  onBeforeMount(() => {
    init();
  })
  // 渲染列表
  const init = async () => {
    state.loading = true;
    const {
      data,
      resultCode
    } = await api.indent.ordersList(state.currentPage, state.pageSize);
    if (resultCode === 200) {
      state.tableData = data.list;
      state.total = data.totalCount;
      state.currentPage = data.currPage;
      state.pageSize = data.pageSize;
      state.loading = false;
    } else {
      ElMessage({
        showClose: true,
        message: '数据渲染失败，请稍后再试！！',
        type: 'error',
      })
      state.loading = false;
    }
  }
  const input = ref('')
  const status = (row) => {
    switch (row) {
      case 0:
        return '待支付';
      case 1:
        return '已支付'
      case 2:
        return '配货完成'
      case 3:
        return '出库成功'
      case 4:
        return '交易成功'
      case -1:
        return '手动关闭'
      case -2:
        return '超时关闭'
      case -3:
        return '商家关闭'
      default:
        break;
    }
  }
  const payType = (row) => {
    switch (row) {
      case 0:
        return '未支付';
      case 1:
        return '微信支付'
      case 2:
        return '支付宝支付'
      default:
        break;
    }
  }
</script>

<style lang="less" scoped>
  .button {
    color: #fff;
  }
</style>